<template><!--测验报告-->
  <div class="warp-2" style="height:100%;overflow-y: auto;" id="test_report_scrolle_box">
        <navbar :title="$t('practice_report')" :backCallback="backList"></navbar>
        <div style="width: 100%;overflow-x: hidden;margin-top: 56px;">
            <div class="box-20 white-bg paddingLR15">
                <!--题目总数-->
                <span style="float: left;">{{ $t('mod_topic_total') }}<em class="color518">({{ practiceInfo.queNum || '0' }})</em></span>
                <!--答对题目-->
                <span style="float: right;">{{ $t('right_num') }} <em class="color518">({{ practiceInfo.correctNum || '0' }})</em></span>
            </div>
            <div class="box-20 white-bg paddingLR15">
                <!--正确率-->
                <span style="float: left;">{{ $t('accuracy') }}<em class="color518">({{ (practiceInfo.accuracy * 100) || 0 }}%)</em></span>
                <!--练习用时-->
                <span style="float: right;">{{ $t('practiced_time') }} <em class="color518">({{ formatTime(practiceInfo.practiceTime) }})</em></span>
            </div>
            <div>
                <div  class="white-bg bottom-shadow" style="padding: 30px 15px;">
                    <p class="font-size16" style="font-weight: bold;margin-bottom: 15px;">{{ $t('exam_attempt_nbr_my_anwser_rpt') }}</p>{{$t('exam_attempt_nbr_my_anwser_rpt')}}
                    <ul class="module-list-16 clearfix">
                        <li class="right clearfix">
                            <div><!--正确题-->
                                <i class="circle"></i>{{ $t('exam_rpt_correct_question') }}({{ correctCnt }})
                            </div>
                        </li>
                        <li class="wrong clearfix">
                            <div><!--错误题-->
                                <i class="circle"></i>{{ $t('exam_rpt_wrong_question') }}({{ incorrectCnt }})
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="margin-top10 white-bg">
                    <div style="padding: 30px 0 40px;">
                        <p class="font-size16 paddingLR15" style="font-weight: bold;">{{ $t('exam_rpt_topic_analysis') }}</p><!--详情题目解析-->
                        <div class="clearfix module-list-17">
                            <!--right 是正确的，wrong 是错误的-->
                            <div>
                                <a @click="goToQuestion(index)" v-for="(row, index) in question.slice(0, 11)" :key="row.resId"
                                :class="[(row.answerList[0].correct) ? 'right' : 'wrong']">{{ ((index+1) > 9) ? (index+1) : ('0' + (index+1)) }}</a>
                            </div>
                            <div v-if="question.length > 12">
                                <template v-if="question.length > 11 && moreQue">
                                <a href="javascript:void(0)" @click="goToQuestion(index + 11)"
                                    :id="navId(index + 12)"
                                    v-for="(row, index) in question.slice(11)" :key="row.resId"
                                    :class="[(row.answerList[0].correct) ? 'right' : 'wrong' ]">{{ index+12 }}</a>
                                </template>
                                <a href="javascript:void(0)" class="more" v-if="question.length > 12 && moreBtn" @click="moreDirectory()">{{ $t('more_text') }}</a><!--更多-->
                            </div>
                        </div>
                    </div>
                    <div>
                        <div style="padding-bottom: 60px;" v-for="(que, index) in question" :key="index" :ref="index">
                            <div class="word-title-10">
                                <p class="paddingLR15 font-size16">
                                    {{ (index + 1) > 9 ? index+1 : ('0' + (index+1)) }}.
                                    <span v-html="imgHandle(que.questionInfoDTO.content)"></span>
                                    [{{ showQuesType(que) }}]
                                    <span :class="[(que.answerList[0].correct) ? 'rightTitle' : 'wrongTitle']"> —— {{ showQueStatus(que) }}</span><!--答案正确/答案错误/答案尚未评分/答案部分正确-->
                                </p>
                            </div>
                            <!--单选题-->
                            <mcSingleQues :que="que" style="padding-top: 5px;" v-if="que.questionInfoDTO.type && que.questionInfoDTO.type === 'MC'"></mcSingleQues>
                            <!--多选题-->
                            <mcManyques :que="que" style="padding-top: 5px;" v-if="que.questionInfoDTO.type && que.questionInfoDTO.type == 'MCQ'"></mcManyques>
                            <!--判断题-->
                            <tfQues :que="que" style="padding-top: 5px;" v-if="que.questionInfoDTO.type && que.questionInfoDTO.type === 'TF'"></tfQues>
                            <!--配对题-->
                            <mtQues :que="que" style="padding-top: 5px;" v-if="que.questionInfoDTO.type && que.questionInfoDTO.type == 'MT'"></mtQues>
                            <!--填空题-->
                            <fbQues :que="que" style="padding-top: 5px;" v-if="que.questionInfoDTO.type && que.questionInfoDTO.type == 'FB'"></fbQues>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="loading" v-if="isLoading">
            <div >
                <div style="width: 33px;height: 33px;">
                    <img src="../../../static/images/loading.gif" alt="" style="width: 100%"/>
                </div>
                <div>{{ $t("lab_loading") }}</div><!--加载中...-->
            </div>
        </div>
  </div>
</template>

<script>
import mcSingleQues from './components/mc-single-ques.vue';
import tfQues from './components/tf-ques.vue';
import mcManyques from './components/mc-many-ques.vue';
import mtQues from './components/mt-ques.vue';
import fbQues from './components/fb-ques.vue';
export default {
    name: 'TestingReport',
    components: {
        mcSingleQues,
        tfQues,
        mcManyques,
        mtQues,
        fbQues
    },
    data() {
        return {
            incorrectCnt: 0, //答错题目数
            correctCnt: 0, //答对题目数
            question: [], //题目和选项
            isLoading: false,
            moreQue: false, //当考试目录大于12条的时候隐藏12条以上的题目目录
            moreBtn: true, //考试目录更多按钮
            practiceInfo: {}
        };
    },
    mounted() {
        this.getExamDetail();
    },
    methods: {
        //获取练习答题详情
        getExamDetail() {
            this.$axios({
                method: 'GET',
                url: `/app/api/trainee/error-question-practice/${this.$route.query.id}/report`
            }).then(res => {
                console.log('res-----', res);
                if (res.data.refList && res.data.refList.length > 0) {
                    this.practiceInfo = res.data;
                    this.question = res.data.refList;
                    if (this.question) {
                        this.changeNavColor();
                    }
                };
            });
        },
        backList() {
            this.$router.push(`/myBank/${localStorage.getItem('loginUser')}`);
        },
        formatTime(timeTotal) {
            let h = parseInt(timeTotal / 60 / 60 % 24);
            h = h < 10 ? '0' + h : h;
            let m = parseInt(timeTotal / 60 % 60);
            m = m < 10 ? '0' + m : m;
            let s = parseInt(timeTotal % 60);
            s = s < 10 ? '0' + s : s;
            const time = h + ':' + m + ':' + s;
            return time;
        },
        /*考试目录id*/
        navId(index) {
            return 'navid_' + index;
        },
        moreDirectory() { //考试目录更多的按钮
            this.moreQue = true;
            this.moreBtn = false;
        },
        //题目目录锚点
        goToQuestion(index) {
            document.querySelector('#test_report_scrolle_box').scrollTop = this.$refs[index][0].offsetTop - 125;
        },
        changeNavColor() {
            // 初始化，防止多次点击数据叠加
            this.incorrectCnt = 0;
            this.correctCnt = 0;
            this.question.map((que, index) => {
                if (que.answerList[0].correct === 0) { // 错误
                    this.incorrectCnt = this.incorrectCnt + 1; // 回答错误题目数
                } else { // 正确
                    this.correctCnt = this.correctCnt + 1; // 回答正确题目数
                }
            });
        },
        imgHandle(txt) {
            let parser = new DOMParser();
            let dom = parser.parseFromString(txt, 'text/html');
            // 处理auido标签
            let audioTags = dom.querySelectorAll('audio');
            audioTags.forEach(audioTag => {
                let src = audioTag.getAttribute('src');
                if (src) {
                    audioTag.setAttribute('src', this.appUrl + src);
                }
            });
            // 处理 <video> 标签
            let videoTags = dom.querySelectorAll('video');
            videoTags.forEach(videoTag => {
                let src = videoTag.getAttribute('src');
                if (src) {
                    videoTag.setAttribute('src', this.appUrl + src);
                }
            });
            // 处理 <img> 标签
            let imgTags = dom.querySelectorAll('img');
            imgTags.forEach(imgTag => {
                let src = imgTag.getAttribute('src');
                if (src) {
                    imgTag.setAttribute('src', this.appUrl + src);
                }
            });
            let htmlContent = dom.documentElement.innerHTML;
            htmlContent = htmlContent.replace(/<head>[.\s\S]*?<\/head>/, '').replace(/<body>|<\/body>/g, '');

            return htmlContent;
        },
        /**
         * 展示题型
         * */
        showQuesType(item) {
            if (item.questionInfoDTO.type === 'MC') {
                return this.$t('Mc_sin');
            } else if (item.questionInfoDTO.type === 'MCQ') {
                return this.$t('Mc');
            } else if (item.questionInfoDTO.type === 'FB') {
                return this.$t('FB');
            } else if (item.questionInfoDTO.type === 'TF') {
                return this.$t('TF');
            } else if (item.questionInfoDTO.type === 'MT') {
                return this.$t('MT');
            }
        },
        /**
         * 展示此题正确状态 */
        showQueStatus(value) {
            if (value.answerList[0].correct) {
                return this.$t('exam_rpt_ok_anwser');
            } else {
                return this.$t('exam_rpt_wrong_anwser');
            }
        }
    },
    watch: {
    },
    //英文序号
    filters: {
        enNo(value) {
            return String.fromCharCode(65 + value);
        }
    }
};
</script>

<style scoped lang="less">
  /*测验报告的刷新*/
  .box-20 {
      height: 44px;
      line-height: 44px;
  }
  .box-21 {
      width: 100%;
      background: #26282e;
      overflow: hidden;
      p {
          height: 41px;
          line-height: 41px;
      }
  }
  .num-list-01 {
      div {
          display: inline-block;;
          width: 58px;
          height: 58px;
          color: #959ba6;
          text-align: center;
          font-size: 16px;
          font-weight: bold;
          position: relative;
          &.cur {
              color: #ffffff;
          }
          b {
              display: block;
              line-height: 58px;
          }
          .num-cur {
              width: 5px;
              height: 5px;
              display: inline-block;
              border-radius: 50%;
              background: rgba(255,255,255,0.3);
              padding: 2px;
              position: absolute;
              bottom: 6px;
              left: 24px;
              em {
                  width: 5px;
                  height: 5px;
                  display: block;
                  border-radius: 50%;
                  background: #ffffff;
              }
          }
      }
  }
  .first-place-icon {
      background-position: 7px -24px;
      position: absolute;
      top: 0;
      left: 15px;
  }
  .box-22 {
      width: 100%;
      height: 100px;
      background: #075ebb;
      color: #ffffff;
      position: relative;
      & > div {
          width: calc(100% - 116px);
          float: left;
          p:nth-of-type(1) {
              font-size: 30px;
          }
      }
      i {
          float: left;
          height: 20px;
          border-left: 1px solid #3f71d5;
          margin-top: 40px;
      }
      & > p {
          width: 115px;
          float: left;
          line-height: 100px;
          text-align: center;
      }
  }
  .triangle-icon {
      width: 20px;
      height: 10px;
      background: url(./images/triangle-icon.png) no-repeat;
      background-size: 100%;
      position: absolute;
      bottom: -1px;
      left: 20px;
  }
  .module-list-16 {
      width: 100%;
      border: 1px solid #e6e6e6;
      border-radius: 4px;
      li {
          width: calc(100% / 2);
          float: left;
          padding: 20px 15px;
          box-sizing: border-box;
          .circle {
              width: 8px;
              height: 8px;
              border: 1px solid #00af78;
              background: #a1e5d0;
              border-radius: 50%;
              display: inline-block;
              margin-right: 5px;
          }
          .proportion {
              width: 100px;
              height: 8px;
              background: #f5f5f5;
              border-radius: 4px;
              margin-top: 8px;
              float: left;
              i {
                  float: left;
                  display: inline-block;
                  height: 8px;
                  border-radius: 4px;
              }
          }
          &.right {
              .proportion {
                  i {
                      background: #00af78;
                  }
              }
          }
          &.wrong {
              .circle {
                  border-color: #fc355d;
                  background: #fff2f5;
              }
              .proportion {
                  i {
                      background: #fc355d;
                  }
              }
          }
          &.part {
              .circle {
                  border-color: #333333;
                  background: #f5f5f5;
              }
              .proportion {
                  i {
                      background: #333333;
                  }
              }
          }
          &.not-yet {
              .circle {
                  border-color: #075ebb;
                  background: #f2f7ff;
              }
              .proportion {
                  i {
                      background: #075ebb;
                  }
              }
          }
      }
      li:nth-of-type(odd) {
          border-right: 1px solid #e6e6e6;
      }
      li:nth-of-type(1), li:nth-of-type(2) {
          border-bottom: 1px solid #e6e6e6;
      }
  }
  .module-list-17 {
      padding: 0 0 0 15px;
      a {
          float: left;
          width: 44px;
          height: 44px;
          border-radius: 50%;
          text-align: center;
          line-height: 44px;
          margin: 15px 13px 0 0;
          font-size: 18px;
          background: #f2fffb;
          border: 1px solid #a1e6d0;
          color: #00af78;
          &.wrong {
              background: #fff2f5;
              border: 1px solid #ffe0e8;
              color: #fc355d;
          }
          &.part, &.more {
              background: #f5f5f5;
              border: 1px solid #e5e5e5;
              color: #333333;
          }
          &.not-yet {
              background: #f2f7ff;
              border: 1px solid #c2d6ff;
              color: #075ebb;
          }
          &.more {
              font-size: 12px;
          }
      }
  }
  .word-title-10 {
      background: #fafafa;
      padding: 15px 0;
  }
  .list-option {
      li {
          .border-box {
              margin: 15px 0 0 0;
              border: 1px solid #e6e6e6;
              border-radius: 4px;
              .title {
                  width: 100%;
                  span {
                      padding: 13px 10px 13px 0;
                      display: block;
                      color: #999999;
                      font-size: 14px;
                  }
              }
          }
      }
  }
  .option-circle {
      display: inline-block;
      padding: 0 0 0 15px;
      box-sizing: border-box;
      &:before {
          content: "";
          display: inline-block;
          width: 16px;
          height: 16px;
          border: 2px solid #cccccc;
          border-radius: 50%;
          margin-bottom: -4px;
      }
      &.cur:before {
          background: url(./images/course-icon.png) no-repeat -2px -338px;
          background-size: 20px;
      }
      &.current:before {
          border-radius: 3px;
      }
      &.current.cur:before {
          background: url(./images/course-icon.png) no-repeat -2px -368px;
          background-size: 20px;
      }
  }
  .answer-box {
      width: 60px;
      height: 100%;
      border-left: 1px solid #e6e6e6;
      span:before {
          content: "";
          display: block;
          width: 15px;
          height: 15px;
          background: url(./images/course-icon.png) no-repeat 0 -318px;
          background-size: 15px;
          margin: 0 auto;
      }
      span.wrong:before {
          background-position: 0 -298px;
      }
  }
  .box-23 {
      .line {
          float: left;
          width: 100%;
          border-top: 1px solid #e6e6e6;
      }
      .title {
          float: left;
          padding-right: 20px;
          background: #ffffff;
          margin-top: -11px;
      }
  }
  .refresh-icon {
      width: 16px;
      height: 14px;
      display: inline-block;
      background: url(./images/course-icon.png) no-repeat 2px -316px;
      background-size: 14px;
      margin-bottom: -1px;
  }
  .box-line {
      font-size: 14px;
      color: #1a1a1a;
      border-bottom: 1px solid #1a1a1a;
      padding: 0 10px;
      margin: 0 8px;
  }
  .rightTitle {
      color: #00af78;
  }
  .wrongTitle {
      color: #fc355d;
  }
  .partTitle {
      color: orange;
  }
  .not-yetTitle {
      color: #075ebb;
  }
  .loading{
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: 999;
      &>div{
          width: 112px;
          height: 112px;
          background: rgba(0,0,0,.5);
          position: absolute;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          margin: auto;
          color: #ffffff;
          display: flex;
          justify-content: center;
          align-items: center;
          flex-direction: column;
          border-radius: 16px;
          &>div:first-child{
              margin-bottom: 5px;
          }
      }
  }
  .re-rating-btn {
      line-height: 20px;
      background: #f7a900;
      color: #fff;
      border-radius: 3px;
      width: 80px;
      background-size: 40px;
      padding: 3px;
  }
  .noData{
    margin: 150px auto;
  }
  .modal-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    &.many-modal-title{
      margin-top: 20px;
    }
    p {
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 25%;
    }
    .title-value {
      display: inline-block;
      width: 100%;
      font-size: 18px;
      font-weight: 400;
      color: #333333;
      text-align: center;
      padding: 10px 0 20px;
      border-right: 1px solid #eeeeee;
    }
    .progress {
      color: #00ba5f;
    }
    .catalog-active {
      color: #075ebb;
    }
    .noboder {
      border: none;
    }
  }
</style>
